package com.jmazgaj.satel.utils;

public class CRCUtils {
	public static final int calculateCRC(int action, byte [] data) {
		int crc = 0xD7E2 + action;
		
		for(int b : data) {
			crc <<= 1;
			if ((crc & 0xFF0000) != 0) {
				crc &= 0xFFFF;
				crc++;
			}
			crc ^= 0xFFFF;
			crc = crc + (crc >> 8) + ((int)b & 0xFF);
			crc &= 0xFFFF;
		}
		return crc;
	}
}
